<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable
{
    use Notifiable,HasApiTokens;
    protected $appends = ['amounts','amounts_format'];
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password','remark','mobile'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
    public function account(){
        return $this->hasMany(Account::class,'user_id','id');
    }
    public function wallet(){
        return $this->hasOne(UserWallet::class,'user_id','id');
    }
    public function getAmountsAttribute($value){
        if($this->wallet) return $this->wallet->amount;
        else return 0;
    }
    public function getAmountsFormatAttribute($value){
        return number_format($this->amounts,2);
    }
}
